"""
Case Type   : 事件触发器
Case Name   : 【事件触发器】\h 查看事件触发器语法帮助信息
Create At   :2024/07/08
Owner       :sungang14
Description :
    预置条件：
        无
    测试步骤：
        1、\h CREATE EVENT TRIGGER查看创建事件触发器帮助信息
        2、\h ALTER EVENT TRIGGER查看创修改事件触发器帮助信息
        3、\h DROP EVENT TRIGGER查看删除事件触发器帮助信息
Expect      : 
    1、触发执行函数f_eventtrigger_0026()
        test_event_trigger: ddl_command_start,CREATE EXTENSION
        test_event_trigger: ddl_command_end,CREATE EXTENSION
    2、触发执行函数f_eventtrigger_0026()
        test_event_trigger: ddl_command_start,ALTER EXTENSION
        test_event_trigger: ddl_command_end,ALTER EXTENSION
    3、触发执行函数f_eventtrigger_0026()
        test_event_trigger: ddl_command_start,DROP EXTENSION
        test_event_trigger: sql_drop,DROP EXTENSION
        test_event_trigger: ddl_command_end,DROP EXTENSION
History     : 
"""

import sys
import os
import unittest
from yat.test import Node
from yat.test import macro

sys.path.append(sys.path[0] + "/../")
from testcase.utils.Logger import Logger
from testcase.utils.Common import Common
from testcase.utils.CommonSH import CommonSH


class IndexFileDamaged(unittest.TestCase):
    def setUp(self):
        self.logger = Logger()
        self.logger.info(f'-----{os.path.basename(__file__)} start-----')
        self.logger.info('----------------this is setup-----------------------')
        self.DB_ENV_PATH = macro.DB_ENV_PATH
        self.DB_INSTANCE_PATH = macro.DB_INSTANCE_PATH
        self.com = Common()
        self.comsh = CommonSH('PrimaryDbBmode')
        self.userNode = self.comsh.node

    def test_Index_file_damaged(self):
        self.logger.info('\h CREATE EVENT TRIGGER查看创建事件触发器帮助信息')
        msg = self.comsh.execut_db_sql('\h CREATE EVENT TRIGGER')
        self.logger.info(msg)
        self.assertEqual(f"Command:     CREATE EVENT TRIGGER\n" \
                         f"Description: define a new event trigger\n" \
                         f"Syntax:\n" \
                         f"CREATE EVENT TRIGGER name\n" \
                         f"    ON event\n" \
                         f"    [ WHEN filter_variable IN (filter_value [, ... ]) [ AND ... ] ]\n" \
                         f"    EXECUTE PROCEDURE function_name()", msg)

        self.logger.info('\h ALTER EVENT TRIGGER查看创修改事件触发器帮助信息')
        msg = self.comsh.execut_db_sql('\h ALTER EVENT TRIGGER')
        self.assertEqual(
            f"Command:     ALTER EVENT TRIGGER\nDescription: change the definition of an event trigger\nSyntax:\n" \
            f"ALTER EVENT TRIGGER name DISABLE\nALTER EVENT TRIGGER name ENABLE [ REPLICA | ALWAYS ]\n" \
            f"ALTER EVENT TRIGGER name OWNER TO {{ new_owner | CURRENT_USER | SESSION_USER }}\n" \
            f"ALTER EVENT TRIGGER name RENAME TO new_name", msg)

        self.logger.info('\h DROP EVENT TRIGGER查看删除事件触发器帮助信息')
        msg = self.comsh.execut_db_sql('\h DROP EVENT TRIGGER')
        self.logger.info(msg)
        self.assertEqual(f"Command:     DROP EVENT TRIGGER\nDescription: remove an event trigger\n" \
                         f"Syntax:\nDROP EVENT TRIGGER [ IF EXISTS ] name [ CASCADE | RESTRICT ]", msg)

    def tearDown(self):
        self.logger.info('----------------this is tearDown-----------------------')
        # 无须后置处理
        self.logger.info(f'-----{os.path.basename(__file__)} end-----')
